unit UItemInsuranceCoverage;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs,udmitems,udmperson, cxGraphics,
  cxControls, cxLookAndFeels, cxLookAndFeelPainters, cxStyles, dxSkinsCore,
  dxSkinBlack, dxSkinBlue, dxSkinBlueprint, dxSkinCaramel, dxSkinCoffee,
  dxSkinDarkRoom, dxSkinDarkSide, dxSkinDevExpressDarkStyle,
  dxSkinDevExpressStyle, dxSkinFoggy, dxSkinGlassOceans, dxSkinHighContrast,
  dxSkiniMaginary, dxSkinLilian, dxSkinLiquidSky, dxSkinLondonLiquidSky,
  dxSkinMcSkin, dxSkinMoneyTwins, dxSkinOffice2007Black, dxSkinOffice2007Blue,
  dxSkinOffice2007Green, dxSkinOffice2007Pink, dxSkinOffice2007Silver,
  dxSkinOffice2010Black, dxSkinOffice2010Blue, dxSkinOffice2010Silver,
  dxSkinPumpkin, dxSkinSeven, dxSkinSevenClassic, dxSkinSharp, dxSkinSharpPlus,
  dxSkinSilver, dxSkinSpringTime, dxSkinStardust, dxSkinSummer2008,
  dxSkinTheAsphaltWorld, dxSkinsDefaultPainters, dxSkinValentine, dxSkinVS2010,
  dxSkinWhiteprint, dxSkinXmas2008Blue, dxSkinscxPCPainter, cxCustomData,
  cxFilter, cxData, cxDataStorage, cxEdit, cxNavigator, Data.DB, cxDBData,
  cxContainer, cxTextEdit, cxDBEdit, Vcl.StdCtrls, cxGridCustomTableView,
  cxGridTableView, cxGridDBTableView, cxGridLevel, cxClasses, cxGridCustomView,
  cxGrid, DBAdvGlowNavigator, AdvPanel, Vcl.ExtCtrls, cxGroupBox, cxMaskEdit,
  cxDropDownEdit, cxLookupEdit, cxDBLookupEdit, cxDBLookupComboBox, Vcl.Menus,
  cxButtons;

type
  TFItemInsuranceCoverage = class(TForm)
    AdvPanel1: TAdvPanel;
    AdvPanelStyler1: TAdvPanelStyler;
    DBAdvGlowNavigator1: TDBAdvGlowNavigator;
    cxGrid1DBTableView1: TcxGridDBTableView;
    cxGrid1Level1: TcxGridLevel;
    cxGrid1: TcxGrid;
    cxGrid1DBTableView1item_id: TcxGridDBColumn;
    cxGrid1DBTableView1insurance_id: TcxGridDBColumn;
    cxGrid1DBTableView1flag: TcxGridDBColumn;
    cxGroupBox1: TcxGroupBox;
    AdvPanel2: TAdvPanel;
    cxLookupComboBox1: TcxLookupComboBox;
    Label1: TLabel;
    cxButton1: TcxButton;
    procedure cxButton1Click(Sender: TObject);
    procedure FormActivate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  FItemInsuranceCoverage: TFItemInsuranceCoverage;

implementation

{$R *.dfm}

procedure TFItemInsuranceCoverage.cxButton1Click(Sender: TObject);
var itemCount : Integer;
var insuranceID :Integer;
var i : Integer;
var itemID : string;
begin
  if (Self.cxLookupComboBox1.EditValue = Null) then
  begin
    ShowMessage('Please Fill All the Requeired Fields');
  end
  else
  begin
    DMItems.his_item_insurance_coverage.Active := False;
    DMItems.his_item_insurance_coverage.ParamByName('a').Value := Self.cxLookupComboBox1.EditValue;
    DMItems.his_item_insurance_coverage.Active := True;

    insuranceID := Self.cxLookupComboBox1.EditValue;
    itemCount := DMItems.his_items.RecordCount;

    DMItems.his_items.First;
    for i := 0 to itemCount - 1 do
    BEGIN
      itemID := DMItems.his_items.FieldByName('item_id').Value;
      if DMItems.his_item_insurance_coverage.Locate('item_id',itemID, [loPartialKey]) = False then
      BEGIN
        DMItems.his_item_insurance_coverage.Insert;
        DMItems.his_item_insurance_coverage.FieldByName('insurance_id').Value := insuranceID;
        DMItems.his_item_insurance_coverage.FieldByName('item_id').Value := itemID;
        DMItems.his_item_insurance_coverage.FieldByName('flag').Value := '1';
        DMItems.his_item_insurance_coverage.Post;
        DMItems.his_item_insurance_coverage.RefreshRecord;
      END;
      DMItems.his_items.Next;
    END;
  end;
  Self.DBAdvGlowNavigator1.Enabled := True;
end;

procedure TFItemInsuranceCoverage.FormActivate(Sender: TObject);
begin
  DMPerson.his_insurance_combine.Refresh;
end;

end.
